<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>setTimeout只执行一次</title>
  </head>
  <body onload="showNum()"><!--页面一加载就调用showNum()-->
    <center>
      <form name="myform" action="http://www.baidu.com">
        <p>注册协议</p>
        <p>*********************************************</p>
        <p>*********************************************</p>
        <p>*********************************************</p>
        <p>*********************************************</p>
        <p>*********************************************</p>
        <p>*********************************************</p>
        <p>*********************************************</p>
        <p>*********************************************</p>
        <p>*********************************************</p>
        <p>*********************************************</p>
        <input type="submit" value="注册10" name="mybtn" disabled="disabled"/>
      </form>
    </center>
  </body>

  <script>
      let num = 10;
      let myIn;

      function showNum() {
          num--;
          if (num <= 0) {
              document.myform.mybtn.value = "注册";
              clearTimeout(myIn);
              document.myform.mybtn.disabled = false;
          } else {
              document.myform.mybtn.value = "注册" + num;
          }
          myIn = setTimeout("showNum()", 1000);
      }
  </script>
</html>
